<%@ page contentType="text/html;charset=UTF-8"%>
<%@ include file="/common/taglibs.jsp"%>
<%@ include file="../common.jsp"%>
<%@ page import="cn.firstsoft.firstframe.admin.*,java.sql.*,javax.sql.*,javax.naming.*" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>管理控制台 - 数据中心</title>
<%@ include file="/common/meta2.jsp"%>
<link href="../style.css" type="text/css" rel=stylesheet>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<table width="100%">
  <tr>
  	<td width="100%">
  		如果下面显示所有的OA或EAS表名列表，则表示此链接正确，显示其他信息都表示不正确！<a href="index.jsp">点这里返回数据中心列表</a><br>
  		如果出现数据源不存在错误，可能您定义完成后没有重新启动服务器造成的！
  	</td>
  </tr>
  <tr>
  	<td>
<%
	int tablecount = 0;
	int error_code = 0;

	String databaseProductName = "";
	String databaseProductVersion = "";
	String driverName = "";
	String driverVersion = "";
	String id = request.getParameter("id");
	String dbtype = request.getParameter("dbtype");
	if (id != null && !"".equals(id)) {
		//判断是Tomcat，还是apusic
		//如果是TOMCAT需要前面加java:comp/env/
		InitialContext ic = null;
		DataSource ds = null;
		Connection conn = null;
		Statement st = null;
		ResultSet rs = null;
		try {
			ic = new InitialContext();
			String jndi_name = "jdbc/" + id;
			if ("TOMCAT".equals(Environment.getWebServerName()))
				jndi_name = "java:comp/env/" + jndi_name;
			ds = (DataSource)ic.lookup(jndi_name); 
			conn = ds.getConnection();
			databaseProductName = conn.getMetaData().getDatabaseProductName();
			databaseProductVersion = conn.getMetaData().getDatabaseProductVersion();
			driverName = conn.getMetaData().getDriverName();
			driverVersion = conn.getMetaData().getDriverVersion();
			st = conn.createStatement();
			
			//什么数据库类型
			String sql = "";
			if ("sqlserver".equals(dbtype)) {
				sql = "SELECT name FROM sysobjects WHERE type = 'U' ORDER BY name";
			} else if ("oracle".equals(dbtype)) {
				sql = "select table_name as name from user_tables ORDER BY table_name";
			}
			
			rs = st.executeQuery(sql);
			out.println("<textarea rows=25 cols=80>");
			while (rs.next()) {
				tablecount = tablecount + 1;
				out.println(rs.getString("name"));
			}
			out.println("</textarea>");
			rs.close();
			st.close();
			conn.close();	
		} catch (Exception e) {
			out.println(e.getMessage());
			e.printStackTrace();
		}	
	} else {
		out.println("传递的参数不正确！");
	}		
%>
    </td>
  </tr>
  <tr>
    <td>
    	测试的数据源：<%=id%>，数据库类型：<%=dbtype %>，表总数量：<%=tablecount %>
    </td>
  </tr>
  <tr>
    <td>
    	数据库名称：<%=databaseProductName%>，数据库版本：<%=databaseProductVersion %>
    </td>
  </tr>  
  <tr>
    <td>
    	驱动器名称：<%=driverName%>，驱动器版本：<%=driverVersion %>
    </td>
  </tr>  
</table>
</body>
</html>
